package mbp.gui.panels;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;

import mbp.base.DateString;
import mbp.core.Offer;

import java.awt.Font;

public class OfferInfoPanel extends JPanel {
	private JTextField txtState;
	private JTextField txtEdate;
	private JTextField txtCDate;
	private JTextField txtUUID;
	private JTextField txtClient;
	private JTextField txtServer;
	private JTextField txtType;

	/**
	 * Create the panel.
	 */
	public OfferInfoPanel() {
		setLayout(null);
		
		txtState = new JTextField();
		txtState.setEditable(false);
		txtState.setColumns(10);
		txtState.setBounds(460, 37, 120, 20);
		add(txtState);
		
		JLabel label = new JLabel("State");
		label.setBounds(460, 21, 46, 14);
		add(label);
		
		txtEdate = new JTextField();
		txtEdate.setEditable(false);
		txtEdate.setColumns(10);
		txtEdate.setBounds(170, 83, 150, 20);
		add(txtEdate);
		
		JLabel label_1 = new JLabel("Expiration date");
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
		label_1.setBounds(170, 67, 114, 15);
		add(label_1);
		
		txtCDate = new JTextField();
		txtCDate.setEditable(false);
		txtCDate.setColumns(10);
		txtCDate.setBounds(10, 83, 150, 20);
		add(txtCDate);
		
		JLabel label_2 = new JLabel("Creation date");
		label_2.setBounds(10, 67, 150, 14);
		add(label_2);
		
		txtUUID = new JTextField();
		txtUUID.setEditable(false);
		txtUUID.setColumns(10);
		txtUUID.setBounds(10, 36, 310, 20);
		add(txtUUID);
		
		JLabel label_3 = new JLabel("UUID");
		label_3.setBounds(10, 21, 70, 14);
		add(label_3);
		
		txtClient = new JTextField();
		txtClient.setEditable(false);
		txtClient.setColumns(10);
		txtClient.setBounds(330, 83, 120, 20);
		add(txtClient);
		
		JLabel label_4 = new JLabel("Client");
		label_4.setBounds(330, 67, 46, 14);
		add(label_4);
		
		txtServer = new JTextField();
		txtServer.setEditable(false);
		txtServer.setColumns(10);
		txtServer.setBounds(460, 83, 120, 20);
		add(txtServer);
		
		JLabel label_5 = new JLabel("Server");
		label_5.setBounds(460, 68, 46, 14);
		add(label_5);
		
		txtType = new JTextField();
		txtType.setEditable(false);
		txtType.setBounds(330, 36, 120, 20);
		add(txtType);
		txtType.setColumns(10);
		
		JLabel lblType = new JLabel("Type");
		lblType.setBounds(330, 21, 46, 14);
		add(lblType);

	}
	
	public void loadOfferInfo(Offer offer)
	{
		txtUUID.setText(offer.GetUUID());
		txtType.setText(offer.getType().getServiceTypeName());
		if(offer.isOfferValid())
		{
			txtState.setText("VALID");
		}
		else
		{
			txtState.setText("NOT VALID");
		}
		txtCDate.setText(DateString.DateToStr(offer.getOfferCreateDate()));
		txtEdate.setText(DateString.DateToStr(offer.getOfferValidityDate()));
		txtClient.setText(offer.getClientName());
		txtServer.setText(offer.getServerName());
	}
	
	public void clearOfferInfo()
	{
		txtUUID.setText("");
		txtType.setText("");	
		txtState.setText("");	
		txtCDate.setText("");
		txtEdate.setText("");
		txtClient.setText("");
		txtServer.setText("");
	}

}
